"""
Open API for WordCraft

"""

import enum


class VariablesGet(enum.Enum):
    """
    Enum for the variables that can be retrieved from the API
    """
    BlocksConfig = "BlocksConfig"


_Globals = {}
_AdminToken = None


def init(admin_token):
    """
    Initialize the API
    """
    global _AdminToken
    _AdminToken = admin_token


class PublicVariable:
    """
    Public Variables
    """

    @staticmethod
    def get(name: VariablesGet, token=None):
        """
        Retrieve a variable from the API
        """
        if token != _AdminToken and name[0] == "_":
            return None
        try:
            return _Globals[name]
        except KeyError:
            return None

    @staticmethod
    def set(name: VariablesGet, value, token=None):
        """
        Set a variable in the API
        """
        global _Globals
        if token != _AdminToken:
            return False
        _Globals[name] = value
        return True
